//2009/09/23 10:02:05
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <math.h>
#include <sstream>
#include <algorithm>

using namespace std;

class MountainRoad
{
public:
    double findDistance(vector <int> start, vector <int> finish)
    {
		vector<pair<int, int> > v(start.size());
		for(int i=0; i<start.size(); i++)
		{
			v[i].first = start[i];
			v[i].second = finish[i];
		}
		sort(v.begin(), v.end());
		double total = v[0].second - v[0].first;
		total *= sqrt(2.0);
		int star = v[0].second;
		for(int i=1; i<v.size(); i++)
		{
			cout << star << endl;
			if(v[i].second <= star) continue;
			else if(v[i].first<=star) 
			{
				total += (v[i].second - star) * sqrt(2.0);
				star = v[i].second;
			}
			else
			{
				total += v[i].first - star;
				total += sqrt(2.0) * (v[i].second - v[i].first);
				star = v[i].second;
			}
		}
		return total;
    }
};
